<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        html,body{
            background-image: url(./images/login-background.jpg) ;
            background-repeat:repeat;
        }
        .box{
            width: 500px;
            height: 400px;
            background-color: white;
            margin: 200px auto;
            border-radius: 10px;
        }
        p{
            text-align: center;
            font-size: 30px;
            line-height: 100px;
        
        }
        input{
           width: 400px; 
           height: 40px;
          margin-left: 50px;
          margin-top:20px;
          border-radius: 5px;
        }
       
    </style>
</head>
<body>
    <div class="box">
        <p>后台管理系统</p>
        <input type="text" placeholder="用户名">
        <input type="password" placeholder="密码">
        <input type="button" value="登陆" style="color:white ;background-color: blue;" class="btns">
    </div>
</body>
</html>
<script src="./axios.min.js"></script>
<script>
    var inputs =document.querySelectorAll('input')
    console.log(inputs);
    var btns= document.querySelector('.btns')
    console.log(btns);
    btns.onclick = function () {
    if (inputs[0].value && inputs[1].value) {
        if (/^1[3-9]\d{9}$/.test(inputs[0].value)&&/^\d{4}$/.test(inputs[1].value)) {
            axios.post('/api/login', { phone: inputs[0].value, pass: inputs[1].value }).then( (res) =>{
                if( res.data.code == 200 ){
                   localStorage.setItem('token',res.data.token)
                        alert('登陆成功');
                        location.replace('http://localhost:9090/首页.html')
                    }else{
                        alert('登陆失败!');
                    }
            })
         }else{
            alert('你输错了')
        }
    } else {
        alert('别空着')

    }
}
</script>
